package com.miao.common.service.impl;

import com.miao.common.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.time.Duration;
import java.util.Map;
import java.util.Random;

@Service
public class MailServiceImpl implements MailService {


   private JavaMailSenderImpl mailSender;


    @Autowired
    public void setMailSender(JavaMailSenderImpl mailSender) {
        this.mailSender = mailSender;
    }


    @Override
    public Integer adopt(Map<String,String> info) throws MessagingException {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        helper.setSubject("秒优购");
        helper.setText("<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
                "    <title>Document</title>\n" +
                "</head>\n" +
                "<body>\n" +
                "    \n" +
                "    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse: collapse;background-color: #ebedf0;font-family:'Alright Sans LP', 'Avenir Next', 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Source Han Sans SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi MicroHei', sans-serif;\">\n" +
                "        <tbody><tr>\n" +
                "          <td>\n" +
                "            <table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"640\">\n" +
                "              <tbody><tr>\n" +
                "                <td style=\"height:20px;\"></td>\n" +
                "              </tr>\n" +
                "      \n" +
                "              <tr>\n" +
                "                <td height=\"10\"></td>\n" +
                "              </tr>\n" +
                "              <tr>\n" +
                "                <td>\n" +
                "                  <table cellpadding=\"0\" cellspacing=\"0\" width=\"640\">\n" +
                "                    <tbody><tr style=\"line-height: 40px;\">\n" +
                "                      <td width=\"80\" style=\"padding-left: 290px;\">\n" +
                "                        <a href=\"http://182.92.221.225/MiaoShop/src/index/index.html\" rel=\"noopener\" target=\"_blank\">\n" +
                "                          <img src=\"https://huangshen.oss-cn-beijing.aliyuncs.com/miao-shop/logo.png\" width=\"54\">\n" +
                "                        </a>\n" +
                "                      </td>\n" +
                "                    </tr>\n" +
                "                  </tbody></table>\n" +
                "                </td>\n" +
                "              </tr>\n" +
                "              <tr>\n" +
                "                <td height=\"40\"></td>\n" +
                "              </tr>\n" +
                "              <tr>\n" +
                "                <td style=\"background-color: #fff;border-radius:6px;padding:40px 40px 0;\">\n" +
                "                  <table>\n" +
                "                    <tbody><tr height=\"40\">\n" +
                "                      <td style=\"padding-left:25px;padding-right:25px;font-size:18px;font-family:'微软雅黑','黑体',arial;\">\n" +
                "                        尊敬的"+info.get("dirName")+"：\n" +
                "                      </td>\n" +
                "                    </tr>\n" +
                "                    <tr height=\"15\">\n" +
                "                      <td></td>\n" +
                "                    </tr>\n" +
                "                    \n" +
                "<tr height=\"30\">\n" +
                "                      <td style=\"padding-left:55px;padding-right:55px;font-family:'微软雅黑','黑体',arial;font-size:14px;line-height:20px;\">\n" +
                "                        您于 <span style=\"border-bottom:1px dashed #ccc;\" t=\"5\" times=\" 20:52\">"+info.get("storeCreatTime")+"</span>  成功完成身份认证。<br>\n" +
                "<p style=\"border-bottom:1px dashed #ccc;\" t=\"5\">\n" +
                "登录账号："+info.get("dirTel")+"</p>\n" +
                "<p style=\"border-bottom:1px dashed #ccc;\" t=\"5\">\n" +
                "默认密码：123456</p>\n" +
                "      \n" +
                "                        \n" +
                "      \n" +
                "                        <a href=\"http://182.92.221.225/MiaoShopAdmin\" target=\"_blank\" style=\"display: inline-block;color:#fff;line-height: 40px;background-color: #1989fa;border-radius: 5px;text-align: center;text-decoration: none;font-size: 14px;padding: 1px 30px;\" rel=\"noopener\">管理店铺</a>\n" +
                "<p t=\"5\">为了您的账号安全请及时修改密码</p>\n" +
                "                      </td>\n" +
                "                    </tr>\n" +
                "                    \n" +
                "                    \n" +
                "                    <tr height=\"20\">\n" +
                "                      <td></td>\n" +
                "                    </tr>\n" +
                "                    <tr>\n" +
                "                      <td style=\"padding-left:55px;padding-right:55px;font-family:'微软雅黑','黑体',arial;font-size:14px;\">\n" +
                "                        此致<br>\n" +
                "                        秒优购团队\n" +
                "                      </td>\n" +
                "                    </tr>\n" +
                "                    <tr height=\"50\">\n" +
                "                      <td></td>\n" +
                "                    </tr>\n" +
                "                  </tbody></table>\n" +
                "                </td>\n" +
                "              </tr>\n" +
                "              <tr>\n" +
                "                <td style=\"height:40px;\"></td>\n" +
                "              </tr>\n" +
                "              \n" +
                "              <tr>\n" +
                "                <td style=\"height:50px;\"></td>\n" +
                "              </tr>\n" +
                "            </tbody></table>\n" +
                "          </td>\n" +
                "        </tr>\n" +
                "      </tbody></table>\n" +
                "</body>",true);
        helper.setTo(info.get("mailAddress"));
        helper.setFrom("Huang-Shen@outlook.com");
        mailSender.send(mimeMessage);
        return 1;
    }

    @Override
    public Integer refuse(Map<String,String> info) throws MessagingException {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        helper.setSubject("秒优购");
        helper.setText("<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
                "    <title>Document</title>\n" +
                "</head>\n" +
                "<body>\n" +
                "    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse: collapse;background-color: #ebedf0;font-family:'Alright Sans LP', 'Avenir Next', 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Source Han Sans SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi MicroHei', sans-serif;\">\n" +
                "        <tbody><tr>\n" +
                "          <td>\n" +
                "            <table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"640\">\n" +
                "              <tbody><tr>\n" +
                "                <td style=\"height:20px;\"></td>\n" +
                "              </tr>\n" +
                "      \n" +
                "              <tr>\n" +
                "                <td height=\"10\"></td>\n" +
                "              </tr>\n" +
                "              <tr>\n" +
                "                <td>\n" +
                "                  <table cellpadding=\"0\" cellspacing=\"0\" width=\"640\">\n" +
                "                    <tbody><tr style=\"line-height: 40px;\">\n" +
                "                      <td width=\"80\" style=\"padding-left: 290px;\">\n" +
                "                        <a href=\"http://182.92.221.225/MiaoShop/src/index/index.html\" rel=\"noopener\" target=\"_blank\">\n" +
                "                          <img src=\"https://huangshen.oss-cn-beijing.aliyuncs.com/miao-shop/logo.png\" width=\"54\">\n" +
                "                        </a>\n" +
                "                      </td>\n" +
                "                    </tr>\n" +
                "                  </tbody></table>\n" +
                "                </td>\n" +
                "              </tr>\n" +
                "              <tr>\n" +
                "                <td height=\"40\"></td>\n" +
                "              </tr>\n" +
                "              <tr>\n" +
                "                <td style=\"background-color: #fff;border-radius:6px;padding:40px 40px 0;\">\n" +
                "                  <table>\n" +
                "                    <tbody><tr height=\"40\">\n" +
                "                      <td style=\"padding-left:25px;padding-right:25px;font-size:18px;font-family:'微软雅黑','黑体',arial;\">\n" +
                "                        尊敬的"+info.get("dirName")+"：\n" +
                "                      </td>\n" +
                "                    </tr>\n" +
                "                    <tr height=\"15\">\n" +
                "                      <td></td>\n" +
                "                    </tr>\n" +
                "                    \n" +
                "<tr height=\"30\">\n" +
                "                      <td style=\"padding-left:55px;padding-right:55px;font-family:'微软雅黑','黑体',arial;font-size:14px;line-height:20px;\"><span style=\"border-bottom:1px dashed #ccc;\" t=\"5\" times=\" 20:52\">非常抱歉，由于您的资料不够完善，认证未通过，请重新提交审核料，进行申请</span><br>\n" +
                "\n" +
                "\n" +
                "      \n" +
                "                        \n" +
                "      \n" +
                "                        \n" +
                "\n" +
                "                      </td>\n" +
                "                    </tr>\n" +
                "                    \n" +
                "                    \n" +
                "                    <tr height=\"20\">\n" +
                "                      <td></td>\n" +
                "                    </tr>\n" +
                "                    <tr>\n" +
                "                      <td style=\"padding-left:55px;padding-right:55px;font-family:'微软雅黑','黑体',arial;font-size:14px;\">\n" +
                "                        此致<br>\n" +
                "                        秒优购团队\n" +
                "                      </td>\n" +
                "                    </tr>\n" +
                "                    <tr height=\"50\">\n" +
                "                      <td></td>\n" +
                "                    </tr>\n" +
                "                  </tbody></table>\n" +
                "                </td>\n" +
                "              </tr>\n" +
                "              <tr>\n" +
                "                <td style=\"height:40px;\"></td>\n" +
                "              </tr>\n" +
                "              \n" +
                "              <tr>\n" +
                "                <td style=\"height:50px;\"></td>\n" +
                "              </tr>\n" +
                "            </tbody></table>\n" +
                "          </td>\n" +
                "        </tr>\n" +
                "      </tbody></table>\n" +
                "</body>",true);
        helper.setTo(info.get("mailAddress"));
        helper.setFrom("Huang-Shen@outlook.com");
        mailSender.send(mimeMessage);

        return 1;
    }


}
